package tema13.Ejercicio7;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import java.awt.Button;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Toolkit;

public class Ej07 extends JFrame {
	private String titulo = "Ventana";
	private final int alto = 250;
	private final int ancho = 250;
	private int x, y, anchoEscritorio, altoEscritorio;

	private void inicializarComponentes() {
		JPanel jp = new JPanel();
		add(jp);
		jp.setBackground(Color.blue);
		jp.setLayout(new GridLayout(3, 3));
		jp.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

		JLabel holaMundo = new JLabel("Hola mundo");
		holaMundo.setForeground(Color.white);

		jp.add(new JLabel());
		jp.add(new JLabel());
		jp.add(new JLabel());
		jp.add(new JLabel());
		jp.add(holaMundo);
		jp.add(new JLabel());
		jp.add(new JLabel());
		jp.add(new JLabel());
		jp.add(new JLabel());

	}

	public Ej07() {
		inicializar();
		inicializarComponentes();
		setVisible(true);

	}

	private void inicializar() {
		setTitle(titulo);
		setSize(ancho, alto);
		inicializarUbicacion();
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	private void inicializarUbicacion() {
		altoEscritorio = Toolkit.getDefaultToolkit().getScreenSize().height;
		anchoEscritorio = Toolkit.getDefaultToolkit().getScreenSize().width;
		y = (altoEscritorio / 2) - (alto / 2);
		x = (anchoEscritorio / 2) - (ancho / 2);
		// x = r.nextInt(anchoEscritorio);
		// y = r.nextInt(altoEscritorio);
		setLocation(x, y);
	}

	public static void main(String[] args) throws Exception {
		new Ej07();
	}
}
